package Coding.file;

import java.io.File;

/**
 * 读文件
 *
 */
public class FileDemo {
    public static void main(String[] args) {

        //访问(运行程序才能访问)当前目录下的demo.text文件
        /**
         * COPY path  获取当前文件的绝对路径 C:\VN2206SE\demo.txt
         * 相对路径 "./" (表示当前目录)
         *  光标 放在后面  ctrl+alt+v  alt+enter
         */
//        new File("C:\\VN2206SE\\demo.txt");
        File file = new File("./demo.txt");
        File file2 = new File("./DirectoryD");
        long length1 = file.length();
        long length2 = file2.length();
        System.out.println("文件的长度"+length1);
        System.out.println("目录的长度"+length2);

        boolean exists = file.exists();
        System.out.println("文件是否存在" + exists);

        boolean file2File = file2.isFile();
        System.out.println("是否是文件"+file2File);

        boolean isDirectory = file2.isDirectory();
        System.out.println("是否是目录" + isDirectory);


        String file2Name = file2.getName();
        System.out.println("文件名" + file2Name);


        String file2Parent = file2.getParent();
        System.out.println("上级目录" + file2Parent); // 点是项目目录


        String file2AbsolutePath = file2.getAbsolutePath();
        System.out.println("文件完整路径" + file2AbsolutePath);


    }
}
